package com.example.lab2;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.content.Intent;
import android.os.Bundle;

import com.google.android.material.floatingactionbutton.FloatingActionButton;

public class MainActivity extends AppCompatActivity {
    private RecyclerView recyclerView;
    private TodolistAdapter todolistAdapter =new TodolistAdapter();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        ItemViewHolder.baseContext=getBaseContext();
        TodolistAdapter.baseContext=getBaseContext();

        recyclerView=findViewById(R.id.recycleView);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        recyclerView.setAdapter(todolistAdapter);

        FloatingActionButton btAdd=findViewById(R.id.toAdd);
        btAdd.setOnClickListener(view -> {
            Intent intent=new Intent();
            intent.setClass(MainActivity.this,AddActivity.class);
            startActivity(intent);
        });
    }

    @Override
    protected void onResume() {
        super.onResume();
        todolistAdapter.refresh();
    }
}